<?php

class dbaCrossSelling {

  function dbaCrossSelling (&$dba){
    $this->dba = &$dba;
  }

  function add ($art_id,$cross_id,$type){
    return $this->dba->query("insert into ".$this->dba->tableforwarder."_shopCrossSelling (article_id,cross_id,type) values ('$art_id','$cross_id','$type');");
  }

  function del ($id){
    return $this->dba->query("delete from ".$this->dba->tableforwarder."_shopCrossSelling where id='$id';");
  }

  // cross-artikel,cross-kategorien,id des Hauptartikels,felder der cross-Artikel
 function getallByFields (&$articles,&$categories,&$reports,$art_id,$artfields){
   $fieldStr = $this->dba->genFieldStr($artfields);
   $this->dba->query("select $fieldStr from ".$this->dba->tableforwarder."_shopArt,".$this->dba->tableforwarder."_shopCrossSelling where article_id = $art_id AND ".$this->dba->tableforwarder."_shopArt.id = cross_id AND type = 'art' order by ".$this->dba->tableforwarder."_shopArt.Name;");
   $articles = $this->dba->fetch_rows_array();
   $this->dba->query("select ".$this->dba->tableforwarder."_shopCat.id,name,display_url,".$this->dba->tableforwarder."_shopCrossSelling.id AS cs_id from ".$this->dba->tableforwarder."_shopCat,".$this->dba->tableforwarder."_shopCrossSelling where article_id = $art_id AND ".$this->dba->tableforwarder."_shopCat.id = cross_id AND type = 'cat' order by ".$this->dba->tableforwarder."_shopCat.name;");
   $categories = $this->dba->fetch_rows_array();
   $this->dba->query("select ".$this->dba->tableforwarder."_shopCrossSelling.id As cs_id,cross_id As id,headline from ".$this->dba->tableforwarder."_berichte,".$this->dba->tableforwarder."_shopCrossSelling where article_id = $art_id AND ".$this->dba->tableforwarder."_berichte.id = cross_id AND type = 'rep' order by ".$this->dba->tableforwarder."_berichte.headline;");
   $reports = $this->dba->fetch_rows_array();
 }

 function getArticlesCatByFields (&$articles,&$reports,$art_id,$artfields){
   $this->dba->query("select cross_id As id from ".$this->dba->tableforwarder."_shopCrossSelling where article_id = $art_id AND type = 'cat';");
   $category = $this->dba->fetch_row_array();
   if ($category['id']){
    $fieldStr = $this->dba->genFieldStr($artfields);
    $check  = $this->dba->query("select $fieldStr from ".$this->dba->tableforwarder."_shopArt,".$this->dba->tableforwarder."_shopCatArt where cat_id=".$category['id']." AND art_id=id;");
    print $this->dba->getError();
   }
   $articles = $this->dba->fetch_rows_Array();
   $this->dba->query("select ".$this->dba->tableforwarder."_shopCrossSelling.id As cs_id,cross_id As id,headline from ".$this->dba->tableforwarder."_berichte,".$this->dba->tableforwarder."_shopCrossSelling where article_id = $art_id AND ".$this->dba->tableforwarder."_berichte.id = cross_id AND type = 'rep' order by ".$this->dba->tableforwarder."_berichte.headline;");
   $reports = $this->dba->fetch_rows_array();
 }

  // cross-artikel,cross-kategorien,id des Hauptartikels,felder der cross-Artikel
 function getallFieldsSF ($art_id,$artfields){
   $this->getallByFields($cross['articles'],$cross['categories'],$cross['reports'],$art_id,$artfields);
   return $cross;
 }

  // cross-artikel,cross-kategorien,id des Hauptartikels,felder der cross-Artikel
 function getArticlesCatFieldsSF ($art_id,$artfields){
   $this->getArticlesCatByFields($cross['articles'],$cross['reports'],$art_id,$artfields);
   return $cross;
 }

}

?>
